package com.briup.day41;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * 服务器端*/
public class ServerDemo1 {
	
	public static void main(String[] args)  {
		try {
			int port = 8888;
			ServerSocket ss = new ServerSocket(port);
			System.out.println("服务器启动成功:"+port);
			System.out.println("等待客户端连接...");
			
			Socket client = ss.accept();
			/*client.getInputStream();
			client.getOutputStream();*/
			
			System.out.println("一台客户端已连接!");
			
			InputStream is = client.getInputStream();
			int i = -1;
			System.out.println("【客户端:】");
			while ((i = is.read()) != -1) {
				System.out.print((char)i);
			}
			
			OutputStream os = client.getOutputStream();
			os.write("hello,client!".getBytes());

		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
